#include <QScrollBar>

#include "myview.h"

MyView::MyView(QWidget *parent):QGraphicsView(parent)
{
    vList.clear();
    eList.clear();
}

MyView::~MyView(){}

bool MyView::isSL()
{
    for(int i = 0;i<vList.size();i++)
    {
        if(vList[i]->outlines.size()==0 || vList[i]->inlines.size()==0)
            return true;
    }
    return false;
}

void MyView::wheelEvent(QWheelEvent *event)
{
    // 获取当前鼠标相对于view的位置;
    QPoint pos1 = event->pos();
    // 获取当前鼠标相对于scene的位置;
    QPointF scenePos = this->mapToScene(pos1);

    int wheelDeltaValue = event->delta();
    // 向上滚动，放大;
    if (wheelDeltaValue > 0)
        this->scale(1.1, 1.1);
    // 向下滚动，缩小;
    else
        this->scale(1.0 / 1.1, 1.0 / 1.1);

    // 将scene坐标转换为放大缩小后的坐标;
    QPointF pos2 = this->matrix().map(scenePos);
    // 通过滚动条控制view放大缩小后的展示scene的位置;
    horizontalScrollBar()->setValue(int(pos2.x() - pos1.x()));
    verticalScrollBar()->setValue(int(pos2.y() - pos1.y()));
}


void MyView::updateIndex(int i)
{
    vList.removeAt(i);
    for(int index = i;index < vList.size();index++){
        vList[index]->index -- ;
    }
}
